angular.module('realtimeDataApp',['dataServiceApp'])
.controller('realtimeDataCtrl',['$scope','$interval','commonDataService',function($scope,$interval,commonDataService){
    $scope.device={};
    commonDataService.getSbh().then(function(result){
        $scope.devices=result;
        $scope.device=result[0];
    });
    $scope.deviceInfo={};
    $scope.$watch('device',function(newValue,oldValue){
        if(newValue.argid==undefined)
        return;
        var data={"sbh":newValue.argid,"num":'1'};        
        commonDataService.getLastData(angular.toJson(data)).then(function(result){
            $scope.deviceInfo=result[0];
        });
    });
    $scope.dataRefresh=function(){
        var data={"sbh":$scope.device.argid,"num":'1'};        
        commonDataService.getLastData(angular.toJson(data)).then(function(result){
            $scope.deviceInfo=result[0];
        });
    };
    $interval($scope.dataRefresh,6000);
}]);
